package com.neulogistics.core.customercenter.api.application.command;

import com.blackto.lib.mediat.unicast.IRequest;
import com.neulogistics.core.customercenter.api.application.validator.annotation.InList;
import com.neulogistics.core.customercenter.api.application.validator.annotation.ValidOrderItem;
import com.neulogistics.core.customercenter.api.application.validator.annotation.ValidateAddress;
import com.neulogistics.core.customercenter.domain.model.enumeration.OrderStatus;
import com.neulogistics.core.customercenter.domain.model.enumeration.OrderType;
import com.neulogistics.core.customercenter.domain.model.valueobject.Address;
import com.neulogistics.core.customercenter.domain.model.valueobject.OrderItem;
import com.neulogistics.infrastructure.common.serviceresult.BaseResponse;
import lombok.Data;

import javax.validation.Valid;
import javax.validation.constraints.*;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

@Data
public class PlaceOrderCommand implements IRequest<BaseResponse<Long>>, Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * 订单类型：1：配送单；2：退货单；3：换货单
     */
    @InList(values = {1, 2, 3})
    @NotNull
    private Integer orderType;

    /**
     * 客户id
     */
    @NotNull
    @Positive
    private Integer customerId;

    /**
     * 订单项，用来储存订单中的商品信息，包含商品id、数量、单价、计量单位
     */
    @NotEmpty
    private List<@Valid @NotNull @ValidOrderItem OrderItem> orderItems;

    /**
     * 备注信息
     */
    @Size(max = 200, message = "备注过长")
    private String orderRemark;

    /**
     * 收货地址{省，市，区，详细}
     */
    @NotNull
    @ValidateAddress
    private Address receiverAddress;

    /**
     * 收货人名
     */
    @NotBlank
    @Size(max = 10, message = "收件人名不能超过10！")
    private String receiverName;

    /**
     * 收货人电话
     */
    @NotBlank(message = "收件人手机号不能为空！")
    @Pattern(regexp = "^1[3-9]\\d{9}$", message = "错误的手机号！")
    private String receiverPhone;

    /**
     * 是否需要发票：0:不需要；1:需要
     */
    @InList(values = {0, 1})
    private Integer optInvoice;

    /**
     * 期望配送时间
     */
    private Date expDeliveryTime;

}
